import {Component, Input, OnInit} from '@angular/core';
import {AdminService} from "../../../../services/admin.service";
import {AlertService} from "../../../../services/alert.service";
import {BakeCupTest} from "../../../../model/BakeCupTest";
import {AuthService} from "../../../../services/auth.service";

@Component({
  selector: 'app-bakecuptestedit',
  templateUrl: './bakecuptestedit.component.html',
  styleUrls: ['./bakecuptestedit.component.css']
})
export class BakecuptesteditComponent implements OnInit {
  @Input() id:string
  b:BakeCupTest
  bcArray:Array<any>
  bcdjArray:Array<any>
  constructor(private adminService: AdminService,
              private alertService: AlertService,
              private authService:AuthService) {
    this.b = new BakeCupTest()
    this.bcArray = new Array()
    this.bcdjArray = new Array()
  }

  ngOnInit(): void {
    this.getBakeCupTestByid()
    this.getbcArray()
    this.getbcdjArray()
  }

  getBakeCupTestByid(){
    this.adminService.getCuptestByid(this.id).then((data:any)=>{
      if(data.msg == "ok"){
        this.b = data.obj
      }else{
        this.alertService.showError("根据id获取失败")
      }
    })
  }

  save(){
    this.adminService.saveCuptest(this.b).then((data:any)=>{
      if(data.msg == "ok"){
        this.alertService.showSuccess("设置杯测成功")
      }else{
        this.alertService.showError("设置杯测失败")
      }
    })
  }

  getbcArray(){
    this.authService.getMemberListByRole("8f716f753b494efea3b5e1de73f4a347").then((data:any)=>{
      if(data.msg == "ok"){
        this.bcArray = data.list
      }else{
        this.alertService.showError(" 获取杯测人员数组失败")
      }
    })
  }
  getbcdjArray(){
    this.adminService.getReferdataSelectByTypeid("fefee636910140e0a316b7b301c1a167").then((data:any)=>{
      if(data.msg == "ok"){
        this.bcdjArray = data.list
      }else{
        this.alertService.showError(" 获取杯测人员数组失败")
      }
    })
  }
  count(){
    this.b.total = (this.b.gx+this.b.sx+this.b.fw+this.b.hg+this.b.sd+this.b.chd+this.b.yzx+this.b.phg+this.b.gjd+this.b.td)/10
  }
}
